//---------------------------------------------------------------------
// Author: jachymko
//
// Description: PS item name expansion handler
//
// Creation Date: Jan 9, 2007
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Text.RegularExpressions;

namespace Pscx.Commands.TabExpansion.Handlers
{
//    [Obsolete("Need to rethink this")]
//    class ItemPathHandler : TabExpansionHandler
//    {
//        private const string ShowHiddenItemsPreference = "PscxShowHiddenItemsPreference";
//        private bool? _hiddenItems;

//        public ItemPathHandler(GetTabExpansionCommand command)
//            : base(command)
//        {

//        }

//        public bool ShowHiddenItems
//        {
//            get
//            {
//                //Command.GetPreferenceVariable<Boolean?>(ref _hiddenItems, string.Empty, ShowHiddenItemsPreference, false);

//                return _hiddenItems ?? false;
//            }
//        }

//        public override void TryExpand(string line, string word)
//        {
//            bool hadSpace = word.IndexOf(' ') > -1;
//            bool qouted = word[0] == '\'' || word[0] == '"';

//            string script = "Get-ChildItem -Path $args[0] -Force:$args[1]";
//            object[] args = new object[]
//            {
//                word + '*', ShowHiddenItems
//            };

//            Collection<PSObject> objects = InvokeArgs(script, args);

//            foreach (PSObject obj in objects)
//            {
//                PSPropertyInfo pspath = obj.Properties["PSPath"];
//                if(pspath != null)
//                {
//                    string path = PreparePath(pspath.Value.ToString());

//                    if (!hadSpace && path.IndexOf(' ') > -1 && path.IndexOf('\\') > -1)
//                    {
//                        path = "'" + path + "'";
//                    }

//                    WriteExpansions(path);
//                }
//            }
//        }

//        private string PreparePath(string pspath)
//        {
//            Match m = _patternProviderPath.Match(pspath);
            
//            if (m.Groups["Path"].Success)
//            {
//                return m.Groups["Path"].Value;
//            }

//            return pspath;
//        }

//        private static readonly Regex _patternProviderPath = new Regex(@"(?x)
//            (?<Provider> [^:]*)
//            ::
//            (?<Path> .*)");

////        private static readonly Regex _patternRemoveQuotes = new Regex(@"(?x)
////            ('|"")?
////            (?<Path> .*)
////            ('|"")");
//    }
}
